package com.loongtech.bi.action.realTime;

import com.loongtech.bi.action.PageHelper;
import com.loongtech.core.util.Time;
import org.datanucleus.util.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Controller
@Scope("view")
public class Data3Action {


    private String hao;
    private List<Data> datasAll;
    private List<Data> datas;

    @PostConstruct
    public void init() {
        initData();
        search();
    }

    public void initData() {
        Random random = new Random();

        datasAll = new ArrayList<>();
        for (int i = 1; i <= 30; i++) {
            Data d = new Data();
            d.setDateStr(Time.getDateStr(Time.currentDate()));
            d.setHao("hao" + i);
            int num = random.nextInt(3 - 1 + 1) + 1;
            d.setT1(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            num = random.nextInt(3 - 1 + 1) + 1;
            d.setT2(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            num = random.nextInt(3 - 1 + 1) + 1;
            d.setT3(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            num = random.nextInt(3 - 1 + 1) + 1;
            d.setT4(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            num = random.nextInt(3 - 1 + 1) + 1;
            d.setT5(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            num = random.nextInt(3 - 1 + 1) + 1;
            d.setT6(num == 1 ? "A" : (num == 2 ? "B" : "C"));
            d.setT15("我建议" + i);
            d.setTime(PageHelper.floatKeepOneNumber((float) ((random.nextInt(10 - 5 + 1) + 10)) * 1.0));

            datasAll.add(d);
        }
    }

    public void search() {
        datas = new ArrayList<>();
        if (!StringUtils.isEmpty(hao)) {
            for (Data data : datasAll) {
                if (hao.equals(data.getHao())) {
                    datas.add(data);
                    break;
                }
            }
        } else {
            datas.addAll(datasAll);
        }
    }

    public class Data {
        private String hao;
        private String dateStr;
        private String t1;
        private String t2;
        private String t3;
        private String t4;
        private String t5;
        private String t6;
        private String t15;
        private float time;

        public String getHao() {
            return hao;
        }

        public void setHao(String hao) {
            this.hao = hao;
        }

        public String getDateStr() {
            return dateStr;
        }

        public void setDateStr(String dateStr) {
            this.dateStr = dateStr;
        }

        public String getT1() {
            return t1;
        }

        public void setT1(String t1) {
            this.t1 = t1;
        }

        public String getT2() {
            return t2;
        }

        public void setT2(String t2) {
            this.t2 = t2;
        }

        public String getT3() {
            return t3;
        }

        public void setT3(String t3) {
            this.t3 = t3;
        }

        public String getT4() {
            return t4;
        }

        public void setT4(String t4) {
            this.t4 = t4;
        }

        public String getT5() {
            return t5;
        }

        public void setT5(String t5) {
            this.t5 = t5;
        }

        public String getT6() {
            return t6;
        }

        public void setT6(String t6) {
            this.t6 = t6;
        }

        public String getT15() {
            return t15;
        }

        public void setT15(String t15) {
            this.t15 = t15;
        }

        public float getTime() {
            return time;
        }

        public void setTime(float time) {
            this.time = time;
        }
    }

    public String getHao() {
        return hao;
    }

    public void setHao(String hao) {
        this.hao = hao;
    }

    public List<Data> getDatasAll() {
        return datasAll;
    }

    public void setDatasAll(List<Data> datasAll) {
        this.datasAll = datasAll;
    }

    public List<Data> getDatas() {
        return datas;
    }

    public void setDatas(List<Data> datas) {
        this.datas = datas;
    }
}
